{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">分类管理</li>
            <li class=""><a href="{:url('admin/used_classify2/add')}">添加分类</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
            <form class="layui-form layui-form-pane" action="{:url('admin/UsedClassify2/index')}" method="get">
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">车型</label>
                    <div class="layui-input-inline">
                        <select name="pid[]" class="site">
                            {if is_array($pid)}
                                {present name="pid[0]"}
                                    {if $pid[0] != 0}
                                    <option value="">{$used_list_arr[$pid[0]]}</option>
                                    {else /}
                                        <option value="0">全部</option>
                                    {/if} 
                                {/present}{notpresent name="pid[0]"}<option value="0">全部</option>{/notpresent}
                            {else /}
                                <option value="0">全部</option>
                            {/if}
                            <!-- <option value="0">全部</option> -->
                            {foreach name="used_list" item="vo"}
                            {if $vo.pid == 0 and $vo.cid == 1}
                            {foreach name='used_list' item='lo'}
                            {if $lo.pid[0] == $vo.id}
                            <option value="{$lo.id}" >{$lo.name}</option>
                            {/if}
                            {/foreach}
                            {/if}
                            {/foreach}
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">品牌</label>
                    <div class="layui-input-inline">
                        <select name="pid[]" class="site">
                            {if is_array($pid)}
                                {present name="pid[1]"}
                                    {if $pid[1] != 0}
                                    <option value="">{$used_list_arr[$pid[1]]}</option>
                                    {else /}
                                        <option value="0">全部</option>
                                    {/if} 
                                {/present}{notpresent name="pid[1]"}<option value="0">全部</option>{/notpresent}
                            {else /}
                                <option value="0">全部3</option>
                            {/if}
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">车系</label>
                    <div class="layui-input-inline">
                        <select name="pid[]" class="site">
                            {if is_array($pid)}
                                {present name="pid[2]"}
                                    {if $pid[2] != 0}
                                    <option value="">{$used_list_arr[$pid[2]]}</option>
                                    {else /}
                                        <option value="0">全部</option>
                                    {/if} 
                                {/present}{notpresent name="pid[2]"}<option value="0">全部</option>{/notpresent}
                            {else /}
                                <option value="0">全部</option>
                            {/if}
                        </select>
                    </div>
                </div>
                <div class="layui-inline" style="margin-bottom: 5px;">
                    <label class="layui-form-label" style="min-width:50px;">型号</label>
                    <div class="layui-input-inline">
                        <select name="pid[]"> 
                            {if is_array($pid)}
                                {present name="pid[3]"}
                                    {if $pid[3] != 0}
                                    <option value="">{$used_list_arr[$pid[3]]}</option>
                                    {else /}
                                        <option value="0">全部</option>
                                    {/if} 
                                {/present}{notpresent name="pid[3]"}<option value="0">全部</option>{/notpresent}
                            {else /}
                                <option value="0">全部</option>
                            {/if}                              
                        </select>
                    </div>
                </div>
                <div class="layui-inline"  style="margin-bottom: 5px;">
                    <button class="layui-btn">搜索</button>
                </div>
            </form>
            <hr>
            <form action="" method="post" class="ajax-form">
                <button type="button" class="layui-btn layui-btn-danger layui-btn-small ajax-action" data-action="{:url('admin/UsedClassify2/delete')}">删除</button>
                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 15px;"><input type="checkbox" class="check-all"></th>
                        <th style="width: 30px;">ID</th>
                        <th style="width: 30px;">排序</th>
                        <th>分类名称</th>
                        <th>所属栏目</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach name="usedclassify_list" item="vo"}
                    <tr>
                        <td><input type="checkbox" name="ids[]" value="{$vo.id}">
                        <td>{$vo.id}</td>
                        <td>{$vo.sort}</td>
                        <td>{$vo.name}</td>
                        <td>
                            {if is_array($vo.pid)}
                                {if $vo.pid[0]}
                                    {$used_list_arr[$vo.pid[0]]}
                                {/if}
                                {if $vo.pid[1]}
                                    - {$used_list_arr[$vo.pid[1]]}
                                {/if}
                                {if $vo.pid[2]}
                                    - {$used_list_arr[$vo.pid[2]]}
                                {/if}
                            {else /}
                                {$usedclassify_level_list[$vo['pid']]} ( 一级栏目 )
                            {/if}
                        </td>
                        <td>
                            <a href="{:url('admin/used_classify2/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                            <a href="{:url('admin/used_classify2/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                <!--分页-->
                {$usedclassify_list->render()}
                </form>
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
$(document).ready(function () {

    form.on('select',function(){
        $("select.site").next().find('dl').on('click','dd',function(){
            var jilu = '.layui-inline';
            var parent_id = $(this).attr('lay-value');
            var index = $(this).parents(jilu).index()+1;

            if(parent_id != 0){             
                $.ajax({
                    url:'/admin/used_classify2/jilm',
                    data:"id="+parent_id,
                    success:function(ell){
                        var i = 0;
                        xuan();

                        for(;i<ell.data.length;i++){
                            $(jilu).eq(index).find('select').append('<option value='+ell.data[i].id+'>'+ell.data[i].name+'</option>');
                            $(jilu).eq(index).find('dl').append('<dd lay-value='+ell.data[i].name+'>'+ell.data[i].name+'</dd>');
                        }
                        form.render('select');
                        
                    }
                });
            }else{
                xuan();
                form.render('select');
            }

            function xuan(){
                // console.log(index);
                if(index != 0){
                    for(var j=0;j<4;j++){
                        if(j > (index-1)){
                            // console.log('j:'+j);
                            $(jilu).eq(j).find('select').html('');
                            $(jilu).eq(j).find('dl').html('');
                            $(jilu).eq(j).find('select').append('<option value="0">全部</option>');
                            $(jilu).eq(j).find('dl').append('<dd lay-value="0">全部</dd>');
                            
                        }
                    }
                }
            }
            
        });
    });



});
</script>
{/block}